Repository navigation
refactor!: replace Trap with extensible ErrorSink and dispatch overrides - #249
Merged
Merged
Conversation
Consolidate `Error` and runtime error handling under a single-word
`error` module in `logforth-core` and `logforth`, replacing `Trap` and
`BestEffortTrap` with `ErrorSink`, `StderrErrorSink`, and
`BlackHoleErrorSink`.
`ErrorSink` defines the best-effort, non-panicking terminal error
handling contract for pipeline execution roots and implements forwarding
for `Arc<T>` and `&'static T` so stateful error sinks can be shared
across dispatches and loggers.
Refine `Error` formatting to walk standard `.source()` causal chains
without special-casing nested `Error` downcasts: `{err}` renders only
the current message, `{err:#}` renders the inline `: `-separated chain
used by `StderrErrorSink`, `{err:?}` renders a multi-line `Caused by:`
report, and `{err:#?}` renders the raw debug structure.
Signed-off-by: tison <wander4096@gmail.com>
Add `LoggerBuilder::error_sink` (defaulting to `StderrErrorSink`) as the logger-wide fallback for append and flush failures, and add `DispatchBuilder::error_sink` as an optional per-dispatch override. Remove the hardcoded `stderr` writes and `.unwrap_or_else(|e| panic!(...))` fallbacks from `Logger::log` and `Logger::flush` so broken standard error pipes cannot crash the host application and sibling appenders and dispatches remain isolated on failure. Signed-off-by: tison <wander4096@gmail.com>
Remove `FileBuilder::trap` so `File` operates as a pure leaf `Append` that surfaces runtime I/O and rotation errors to its owning `Dispatch` or `Async` worker. Update `RollingFileWriter::write_all` to defer any date/size rollover or old-log cleanup error until after writing the current record to the active file, preventing data loss when log rotation fails. Signed-off-by: tison <wander4096@gmail.com>
Replace `AsyncBuilder::trap` with `AsyncBuilder::error_sink` (defaulting to `StderrErrorSink`) and wrap background worker append and flush failures with consistent causal context before forwarding to the sink. Expose `.error_sink(...)` on `LogStarterBuilder`, `LogStarterTestingBuilder`, and `LogStarterStdStreamBuilder` so applications using `starter_log` can customize pipeline error handling. Signed-off-by: tison <wander4096@gmail.com>
Document the best-effort, non-panicking `ErrorSink` contract in `DESIGN.md` and record the `ErrorSink` migration in `CHANGELOG.md`. Signed-off-by: tison <wander4096@gmail.com>
tisonkun
force-pushed
the
refactor/core-error-sink
branch
from
November 25, 2026 07:34
4b323ff to
06a43ee
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Internal runtime failures were previously split across
Trap(configured separately onAsyncBuilderandFileBuilder) and hardcodedstderrwrites withpanic!fallbacks insideLogger, allowing brokenstderrpipes to crash host processes while hiding log rotation failures insideRollingFileWriter.This change unifies pipeline error reporting around
ErrorSinkunderpub mod errorperDESIGN.md:TrapandBestEffortTrapwithpub trait ErrorSink: fmt::Debug + Send + Sync + 'staticunderlogforth_core::error(logforth::error), accompanied by zero-sized#[non_exhaustive]StderrErrorSinkandBlackHoleErrorSinkstructs, forwarding implementations forArc<T>and&'static T, and an explicit best-effort terminal contract.Errorcausal chain formatting ({err}single-layer message,{err:#}inline chain used byStderrErrorSink,{err:?}multi-lineCaused by:report).LoggerBuilder::error_sinkas the logger-wide failure fallback andDispatchBuilder::error_sinkas an optional per-dispatch override, removingLogger'sstderrpanic!paths..error_sink(...)ontoAsyncBuilderandstarter_logbuilders.FileBuilder::trapsoFilesurfaces errors uniformly through its owningDispatchorAsyncworker, and ensureRollingFileWriterwrites the current record to the active file before returning any rollover or cleanup error.